/*
 * draw_utils.h
 *
 *  Created on: 26-nov-2008
 *      Author: HPK
 */

#ifndef DRAW_UTILS_H_
#define DRAW_UTILS_H_

class DrawUtils{
	public:
		static void drawHalfColumn(){
			float material_color[4]={0.5,0.5,0.5,0};
			Point points[8]={Point(0.5,0.25,0),Point(0.5,0.5,0),Point(-0.5,0.5,0),Point(-0.5,0.25,0),
					Point(0,0,1),Point(0,0,1),Point(0,0,1),Point(0,0,1)};
			glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,material_color);
			drawSolid(points,Point(0,0.375,0),Point(0,0,0.9),4);
		}

		static void drawCube(Point points[4]){
			// Tapas
			glBegin(GL_QUADS);
				//Tapa 1
				glColor3f(1,0,0);
				glVertex3f(points[0].x1,points[0].x2,points[0].x3);
				glColor3f(0,1,0);
				glVertex3f(points[1].x1,points[1].x2,points[1].x3);
				glColor3f(0,0,1);
				glVertex3f(points[2].x1,points[2].x2,points[2].x3);
				glColor3f(0,1,1);
				glVertex3f(points[3].x1,points[3].x2,points[3].x3);
				glColor3f(1,0,0);
				// Tapa 2
				glVertex3f(points[4].x1,points[4].x2,points[4].x3);
				glColor3f(0,1,0);
				glVertex3f(points[5].x1,points[5].x2,points[5].x3);
				glColor3f(0,0,1);
				glVertex3f(points[6].x1,points[6].x2,points[6].x3);
				glColor3f(0,1,1);
				glVertex3f(points[7].x1,points[7].x2,points[7].x3);
			glEnd();

			for(unsigned int c=0;c<4;c++){
				glBegin(GL_QUADS);
					glColor3f(1,0,0);
					glVertex3f(points[c+0].x1,points[c+0].x2,points[c+0].x3);
					glColor3f(0,1,0);

					if((c+1)<4){
						glVertex3f(points[c+1].x1,points[c+1].x2,points[c+1].x3);
						glColor3f(0,0,1);
						glVertex3f(points[c+5].x1,points[c+5].x2,points[c+5].x3);
						glColor3f(0,1,1);
						glVertex3f(points[c+4].x1,points[c+4].x2,points[c+4].x3);
					}else{
						glVertex3f(points[0].x1,points[0].x2,points[0].x3);
						glColor3f(0,0,1);
						glVertex3f(points[4].x1,points[4].x2,points[4].x3);
						glColor3f(0,1,1);
						glVertex3f(points[7].x1,points[7].x2,points[7].x3);
					}
				glEnd();
			}
		}


		static void drawSolid(const Point points[],const Point& centerA,const Point& centerB,unsigned int size){
			std::vector<unsigned int> index;
			std::vector<Point> normal;
			/*
			INDEX PARA UNA TAPA
			for(unsigned int i=1; i<size;i++){
				for(unsigned int j=0;j<1;j++){
					index.push_back((i-1)*size+j);
					index.push_back(i*size+j);
				}
			}
			*/
			index.push_back(0);
			index.push_back(1);
			index.push_back(4);
			index.push_back(5);
			index.push_back(6);
			index.push_back(1);
			index.push_back(2);
			index.push_back(3);

			index.push_back(6);
			index.push_back(7);
			index.push_back(4);
			index.push_back(3);
			index.push_back(0);

			for(unsigned int i=0; i<size;i++){
				normal.push_back(centerA-points[i]);
			}
			for(unsigned int i=size; i<size*2;i++){
				normal.push_back(centerB-points[i]);
			}

			glEnable(GL_NORMALIZE);
			glEnableClientState(GL_VERTEX_ARRAY);
			glEnableClientState(GL_NORMAL_ARRAY);

			glVertexPointer(3, GL_FLOAT, 0, (float*)points);
			glNormalPointer(GL_FLOAT, 0, (float*)normal._M_impl._M_start);
			glDrawElements(GL_TRIANGLE_STRIP, 13, GL_UNSIGNED_INT, index._M_impl._M_start);

			glDisableClientState(GL_NORMAL_ARRAY);
			glDisableClientState(GL_VERTEX_ARRAY);
			glDisable(GL_NORMALIZE);

		}
};

#endif /* DRAW_UTILS_H_ */
